package sys.cloud.escape;

import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;
import java.util.Enumeration;

/**
 * Created by shiyusen on 2017/3/23.
 */
public class WebUtils {
    public static void requestParam2Bean(HttpServletRequest request,
                                         LeavelMessage message) {
        Enumeration<String> e = request.getParameterNames();
        while (e.hasMoreElements()) {
            String name = e.nextElement();
            String value = request.getParameter(name);
            try {
                value = new String(value.getBytes("ISO-8859-1"),"UTF-8");
            } catch (UnsupportedEncodingException e1) {
            }
            if(name.equals("username")) message.setUsername(value);
            if(name.equals("topic")) message.setTopic(value);
            if(name.equals("content")) message.setContent(value);
        }
    }
}
